﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>产品订单</title>
	<link rel="stylesheet" href="/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
	<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
	<style>
		input.error{
			border: 1px solid #E6594E;
		}
	</style>
</head>
<body>
    <div class="container">
	
		<form id="UserOrderForm">
		  <br/>
		  <div class="form-group">
			<label for="id">订单编号</label>
			<input type="text" class="form-control" id="id" name="id" placeholder="订单编号">
		  </div>
		  	  <div class="form-group">
			<label for="status">状态：</label>
			<input type="text" class="form-control" id="status" name="status" placeholder="状态">
		  </div>
		  <div class="form-group">
			<label for="user_id">用户：</label>
			<input type="text" class="form-control" id="user_id" name="user_id" placeholder="用户">
		  </div>
		  <div class="form-group">
			<label for="totalPrice">价格：</label>
			<input type="text" class="form-control" id="totalPrice" name="totalPrice" placeholder="价格">
		  </div>
		  <div class="form-group">
			<label for="expressFee">邮费：</label>
			<input type="text" class="form-control" id="expressFee" name="expressFee" placeholder="邮费">
		  </div>
		  <div class="form-group">
		  <button type="button" id="saveBtn" class="btn btn-success">确认</button>
		  <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
		  </div>
		</form>
    </div>

		<script>
			var editUserOrder = function(){
				if(!check().form()){ 
					return;  
				}
				$.ajax({
					   type: "GET",
					   dataType: "json",
					   url: "/user/edit",
					   data: {
							"id": ${data.id},
							"status": $("#status").val(),
							"user":$("#user_id").val(),
							"price":$("#totalPrice").val(),
							"fee":$("#expressFee").val(),
					   },
					   success: function(msg){
							$('#cancelBtn').click();			
					   }
				});
			}
			
			$('#saveBtn').on('click', function(){
				editUserOrder();
			});
			
			$('#cancelBtn').on('click', function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.layer.close(index);
			});

			
			//校验字段是否正确 
            function check(){ 
                /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/ 
                return $("#editUserForm").validate({ 
                            rules:{ 
                                id:{ 
                                    required:true
                                },
                                status:{ 
                                    required:true                                   
                                }, 
                                user_id:{ 
                                    required:true                                   
                                },
                                totalPrice:{ 
                                    required:true                                   
                                },
                                 expressFee:{ 
                                    required:true                                   
                                }
                            }, 
                            messages:{ 
                                id:{ 
                                    required:""
                                },
                                status:{ 
                                    required:""                                
                                },
                                 user_id:{ 
                                    required:""                                
                                },
                                 totalPrice:{ 
                                    required:""                                
                                },
                                 express:{ 
                                    required:""                                
                                },
                            }     
                        }); 
            } 
			
		</script> 	
</body>
</html>